/**
 * Package:com.goldcitynet.model;
 * $Id$
 * Copyright(c) 2001-2005 www.afteryuan.com
 */
package com.afteryuan.engine.model;

import com.afteryuan.dao.BaseObject;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;

import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.GenericGenerator;

import java.util.Date;

/**
 * 场景的一个实例,在socket服务器端初始化,用户登录场景的时候分散进入每个实例.
 * 每个场景实例的容纳人数可以控制,以期获得更好的性能.
 * <p/>
 * <p><a href="SceneInstance.java.html"><i>View Source</i></a></p>
 *
 * @author <a href="mailto:afteryuan@afteryuan.com">$Author$</a>
 * @version $Revision$
 */
@Entity
@Table(name = "T_SceneInstance")
@Proxy(lazy = false)
public class SceneInstance extends BaseObject {
    /**
     * 社区
     */
    public static final Integer SCENE_THEME_COMMUNITY=0;
    /**
     * 游戏
     */
    public static final Integer SCENE_THEME_GAME=1;
    /**
     * 地产
     */
    public static final Integer SCENE_THEME_LAND=2;
    
    public final static String[] THEME_FRIENDNAMES = {"社区","游戏","地产"};
    /*场景容纳最大玩家数*/
    private Integer maxPlayers;

    private String name;

    private Integer status;

    /*实例指向的场景*/
    private Scene scene;

    private String id;

    private Long createTime;
    
	/** 上级场景ID */
	private SceneInstance upLevelScene;		
    /**场景在世界中的坐标X*/
    private Integer dircX;
    /**场景在世界中的坐标Y*/
    private Integer dircY;
    /**点击率*/
    private Long frequency;

    public SceneInstance() {
		setCreateTime(new Date().getTime());
	}

	public SceneInstance(String id) {
        this.id=id;
        setCreateTime(new Date().getTime());
	}

    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }


    public Integer getMaxPlayers() {
        return maxPlayers;
    }

    public void setMaxPlayers(Integer maxPlayers) {
        this.maxPlayers = maxPlayers;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @ManyToOne
    @JoinColumn(name="scene")
    public Scene getScene() {
        return scene;
    }

    public void setScene(Scene scene) {
        this.scene = scene;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    @ManyToOne
    @JoinColumn(name="upLevelScene")
	public SceneInstance getUpLevelScene() {
		return upLevelScene;
	}

	public void setUpLevelScene(SceneInstance upLevelScene) {
		this.upLevelScene = upLevelScene;
	}

	public Integer getDircX() {
		return dircX;
	}

	public void setDircX(Integer dircX) {
		this.dircX = dircX;
	}

	public Integer getDircY() {
		return dircY;
	}

	public void setDircY(Integer dircY) {
		this.dircY = dircY;
	}

	public Long getFrequency() {
		return frequency;
	}
	
	public void setFrequency(Long frequency) {
		this.frequency = frequency;
	}

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        SceneInstance that = (SceneInstance) o;

        if (id != null ? !id.equals(that.id) : that.id != null) return false;

        return true;
    }


    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }

    @Override
    public String toString() {
        return "SceneInstance{" +
                "maxPlayers=" + maxPlayers +
                ", name='" + name + '\'' +
                ", status=" + status +
                ", id='" + id + '\'' +
                '}';
    }

}
